package com.ruoyi.pidaijiData.service.impl;

import com.deepoove.poi.data.PictureRenderData;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.utils.*;
import com.ruoyi.pidaijiData.domain.pad.PidaijiTaskReqDTO;
import com.ruoyi.pidaijiData.domain.pad.PidaijiTaskRespDTO;
import com.ruoyi.pidaijiData.domain.pad.PidaijiTreeDataItemDto;
import com.ruoyi.pidaijiData.domain.plat.*;
import com.ruoyi.pidaijiData.domain.report.PidaijiReportData;
import com.ruoyi.pidaijiData.service.*;
import com.ruoyi.task.domain.entity.DataTaskEntity;
import com.ruoyi.task.service.IDataTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;


/**
 * 皮带机数据Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-12-28
 */
@Service
public class DataPidaijiServiceImpl implements IDataPidaijiService
{

    @Autowired
    private IDataTaskService dataTaskService;

    @Autowired
    private IDataPidaijiChengzhongService dataPidaijiChengzhongService;

    @Autowired
    private IDataPidaijiJxtdService dataPidaijiJxtdService;

    @Autowired
    private IDataPidaijiNhService dataPidaijiNhService;

    @Autowired
    private IDataPidaijiPpzylService dataPidaijiPpzylService;

    @Autowired
    private IDataPidaijiDmbhzylService dataPidaijiDmbhzylService;

    @Autowired
    private IDataPidaijiSuduService dataPidaijiSuduService;

    @Autowired
    private IDataPidaijiYyService dataPidaijiYyService;

    @Autowired
    private IDataPidaijiZxService dataPidaijiZxService;

    /**
     * 详情数据
     *
     * @param dataTaskId
     * @return
     * @throws ExecutionException
     * @throws InterruptedException
     */
    @Override
    public PidaijiTaskReqDTO getDetailPidaiji(Long dataTaskId) throws ExecutionException, InterruptedException {
        long startTime = System.currentTimeMillis();
        //测试数据基本信息
        Future<DataTaskEntity> taskFuture = dataTaskService.selectDataTask(dataTaskId);
        //称重测试数据
        Future<List<DataPidaijiChengzhong>> chengzhongListFuture = dataPidaijiChengzhongService.selectDataPidaijiChengzhongByDataTaskId(dataTaskId);
        //径向跳动测试项
        Future<List<DataPidaijiJxtd>> jxtdListFuture = dataPidaijiJxtdService.selectDataPidaijiJxtdByDataTaskId(dataTaskId);
        //能耗测试数据
        Future<List<DataPidaijiNh>> nhListFuture = dataPidaijiNhService.selectDataPidaijiNhByDataTaskId(dataTaskId);
        //跑偏保护作用力测试数据
        Future<List<DataPidaijiPpzyl>> ppzylListFuture = dataPidaijiPpzylService.selectDataPidaijiPpzylByDataTaskId(dataTaskId);
        //堆煤保护作用力测试数据
        Future<List<DataPidaijiDmbhzyl>> dmbhzylListFuture = dataPidaijiDmbhzylService.selectDataPidaijiDmbhzylByDataTaskId(dataTaskId);
        //速度测试数据
        Future<List<DataPidaijiSudu>> suduListFuture = dataPidaijiSuduService.selectDataPidaijiSuduByDataTaskId(dataTaskId);
        //油压测试数据
        Future<List<DataPidaijiYy>> yyListFuture = dataPidaijiYyService.selectDataPidaijiYyByDataTaskId(dataTaskId);
        //轴向数据
        Future<List<DataPidaijiZx>> zxListFuture = dataPidaijiZxService.selectDataPidaijiZxByDataTaskId(dataTaskId);
        //添加到集合对象中
        List<Future<?>> futureList = new ArrayList<>();
        futureList.add(taskFuture);
        futureList.add(chengzhongListFuture);
        futureList.add(jxtdListFuture);
        futureList.add(nhListFuture);
        futureList.add(ppzylListFuture);
        futureList.add(dmbhzylListFuture);
        futureList.add(suduListFuture);
        futureList.add(yyListFuture);
        futureList.add(zxListFuture);
        // 从future提取所有数据
        PidaijiTaskRespDTO pidaijiTaskRespDTO = new PidaijiTaskRespDTO();
        for (Future<?> future : futureList) {
            while (true) {
                if (taskFuture.isDone() && !taskFuture.isCancelled()) {
                    // 获取结果
                    Object resultObject = future.get();
                    // 任务数据
                    if (resultObject instanceof DataTaskEntity) {
                        pidaijiTaskRespDTO.setDataTaskEntity((DataTaskEntity) resultObject);
                    }
                    if (resultObject instanceof List) {
                        List<Object> resultList = (List<Object>) resultObject;
                        if (!resultList.isEmpty()) {
                            Object item = resultList.get(0);
                            //测试任务类型获取数据
                            if (item instanceof DataPidaijiChengzhong) {
                                pidaijiTaskRespDTO.setChengZhongEntityList(ListUtils.castList(resultList, DataPidaijiChengzhong.class));
                            }
                            if (item instanceof DataPidaijiJxtd) {
                                pidaijiTaskRespDTO.setJingXiangEntityList(ListUtils.castList(resultList, DataPidaijiJxtd.class));
                            }
                            if (item instanceof DataPidaijiNh) {
                                pidaijiTaskRespDTO.setNengHaoEntityList(ListUtils.castList(resultList, DataPidaijiNh.class));
                            }
                            if (item instanceof DataPidaijiPpzyl) {
                                pidaijiTaskRespDTO.setPpbhzylEntityList(ListUtils.castList(resultList, DataPidaijiPpzyl.class));
                            }
                            if (item instanceof DataPidaijiDmbhzyl) {
                                pidaijiTaskRespDTO.setDmbhzylEntityList(ListUtils.castList(resultList, DataPidaijiDmbhzyl.class));
                            }
                            if (item instanceof DataPidaijiSudu) {
                                pidaijiTaskRespDTO.setSpeedEntityList(ListUtils.castList(resultList, DataPidaijiSudu.class));
                            }
                            if (item instanceof DataPidaijiYy) {
                                pidaijiTaskRespDTO.setYouYaEntityList(ListUtils.castList(resultList, DataPidaijiYy.class));
                            }
                            if (item instanceof DataPidaijiZx) {
                                pidaijiTaskRespDTO.setZhouXiangEntityList(ListUtils.castList(resultList, DataPidaijiZx.class));
                            }
                        }
                    }
                    break;
                } else {
                    // 轮询查询结果
                    Thread.sleep(10);
                }
            }
        }
        //目录结构拼接
        List<PidaijiTreeDataItemDto> treeDataList = new ArrayList<>();
        //称重测试数据
        if (null != pidaijiTaskRespDTO.getChengZhongEntityList() && !pidaijiTaskRespDTO.getChengZhongEntityList().isEmpty()) {
            PidaijiTreeDataItemDto treeDataItemDto = new PidaijiTreeDataItemDto("chengZhongEntityList");
            pidaijiTaskRespDTO.getChengZhongEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new PidaijiTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            PidaijiTreeDataItemDto treeDataItemDto = new PidaijiTreeDataItemDto("chengZhongEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //速度数据
        if (null != pidaijiTaskRespDTO.getSpeedEntityList() && !pidaijiTaskRespDTO.getSpeedEntityList().isEmpty()) {
            PidaijiTreeDataItemDto treeDataItemDto = new PidaijiTreeDataItemDto("speedEntityList");
            pidaijiTaskRespDTO.getSpeedEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new PidaijiTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            PidaijiTreeDataItemDto treeDataItemDto = new PidaijiTreeDataItemDto("speedEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //径向跳动测试数据
        if (null != pidaijiTaskRespDTO.getJingXiangEntityList() && !pidaijiTaskRespDTO.getJingXiangEntityList().isEmpty()) {
            PidaijiTreeDataItemDto treeDataItemDto = new PidaijiTreeDataItemDto("jingXiangEntityList");
            pidaijiTaskRespDTO.getJingXiangEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new PidaijiTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            PidaijiTreeDataItemDto treeDataItemDto = new PidaijiTreeDataItemDto("jingXiangEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //轴向数据
        if (null != pidaijiTaskRespDTO.getZhouXiangEntityList() && !pidaijiTaskRespDTO.getZhouXiangEntityList().isEmpty()) {
            PidaijiTreeDataItemDto treeDataItemDto = new PidaijiTreeDataItemDto("zhouXiangEntityList");
            pidaijiTaskRespDTO.getZhouXiangEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new PidaijiTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            PidaijiTreeDataItemDto treeDataItemDto = new PidaijiTreeDataItemDto("zhouXiangEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //油压数据
        if (null != pidaijiTaskRespDTO.getYouYaEntityList() && !pidaijiTaskRespDTO.getYouYaEntityList().isEmpty()) {
            PidaijiTreeDataItemDto treeDataItemDto = new PidaijiTreeDataItemDto("youYaEntityList");
            pidaijiTaskRespDTO.getYouYaEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new PidaijiTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            PidaijiTreeDataItemDto treeDataItemDto = new PidaijiTreeDataItemDto("youYaEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //能耗测试数据
        if (null != pidaijiTaskRespDTO.getNengHaoEntityList() && !pidaijiTaskRespDTO.getNengHaoEntityList().isEmpty()) {
            PidaijiTreeDataItemDto treeDataItemDto = new PidaijiTreeDataItemDto("nengHaoEntityList");
            pidaijiTaskRespDTO.getNengHaoEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new PidaijiTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            PidaijiTreeDataItemDto treeDataItemDto = new PidaijiTreeDataItemDto("nengHaoEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //跑偏保护作用力测试项
        if (null != pidaijiTaskRespDTO.getPpbhzylEntityList() && !pidaijiTaskRespDTO.getPpbhzylEntityList().isEmpty()) {
            PidaijiTreeDataItemDto treeDataItemDto = new PidaijiTreeDataItemDto("ppbhzylEntityList");
            pidaijiTaskRespDTO.getPpbhzylEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new PidaijiTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            PidaijiTreeDataItemDto treeDataItemDto = new PidaijiTreeDataItemDto("ppbhzylEntityList");
            treeDataList.add(treeDataItemDto);
        }
        //堆煤保护作用力测试项
        if (null != pidaijiTaskRespDTO.getDmbhzylEntityList() && !pidaijiTaskRespDTO.getDmbhzylEntityList().isEmpty()) {
            PidaijiTreeDataItemDto treeDataItemDto = new PidaijiTreeDataItemDto("dmbhzylEntityList");
            pidaijiTaskRespDTO.getDmbhzylEntityList().forEach(item-> treeDataItemDto.getTestItemList().add(new PidaijiTreeDataItemDto.ProjectTestItem(item.getId(), item.getSaveTime(), "")));
            treeDataList.add(treeDataItemDto);
        }else {
            PidaijiTreeDataItemDto treeDataItemDto = new PidaijiTreeDataItemDto("dmbhzylEntityList");
            treeDataList.add(treeDataItemDto);
        }
        pidaijiTaskRespDTO.setPidaijiTreeDataList(treeDataList);
        System.out.printf("任务ID为 %d 的“皮带机测试任务”查询耗时 %d。", dataTaskId, (System.currentTimeMillis() - startTime));
        return pidaijiTaskRespDTO;
    }

    /**
     * 删除皮带机数据，变更数据状态为2
     *
     * @param dataTaskId
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int delAllPidaijiData(Long dataTaskId) {
        //测试数据基本信息
        //变更任务状态
        try {
            Long[] dataTaskIds = new Long[] {dataTaskId};
            dataTaskService.deleteDataTaskByDataTaskIds(dataTaskIds, "008");
            //称重测试数据
            dataPidaijiChengzhongService.updateDataPidaijiChengzhongByDataTaskId(dataTaskId);
            //径向跳动测试项
            dataPidaijiJxtdService.updateDataPidaijiJxByDataTaskId(dataTaskId);
            //能耗测试数据
            dataPidaijiNhService.updateDataPidaijiNhByDataTaskId(dataTaskId);
            //跑偏保护作用力测试数据
            dataPidaijiPpzylService.updateDataPidaijiNhByDataTaskId(dataTaskId);
            //堆煤保护作用力测试数据
            dataPidaijiDmbhzylService.updateDataPidaijiDmbhzylByDataTaskId(dataTaskId);
            //速度测试数据
            dataPidaijiSuduService.updateDataPidaijiSuduByDataTaskId(dataTaskId);
            //油压测试数据
            dataPidaijiYyService.updateDataPidaijiYyByDataTaskId(dataTaskId);
            //轴向数据
            dataPidaijiZxService.updateDataPidaijiZxByDataTaskId(dataTaskId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return 1;
    }

    /**
     * 导入报告到皮带机
     *
     * @param data
     */
    @Override
    public String dataPidaijiImportReport(PidaijiReportData data) {
        // 报告模板名称
        String template = data.getTempId();
        //测试任务信息
        DataTaskEntity dataTaskEntity = dataTaskService.selectDataTaskByDataTaskId(data.getDataTaskEntity().getDataTaskId());
        data.setDataTaskEntity(dataTaskEntity);
        //获取生成的工况图并转换png格式
        String rootPath = RuoYiConfig.getProfile() + RuoYiConfig.getChartPath() + "/";
        //导入报告中
        Map<String, Object> params = new HashMap<>();
        // 大曲线图的长宽
        int picW = 450;
        int picH = 250;
        // 小曲线图的长款
        int picSW = 280;
        int picSH = 156;
        //基本检测信息
        if(null != data.getDataTaskEntity()) {
            params.put("受检单位", data.getDataTaskEntity().getShjdw());
            params.put("设备名称", data.getDataTaskEntity().getShbbh());
            params.put("主检姓名", data.getDataTaskEntity().getZhjxm());
            params.put("测试人员", data.getDataTaskEntity().getCshry());
            params.put("检测日期", DateUtils.dateTime(data.getDataTaskEntity().getTaskCreateTime()));
        }
        //皮带机参数
        List<Map<String, Object>> chengzhongList = new ArrayList<>();
        List<Map<String, Object>> ppList = new ArrayList<>();
        List<Map<String, Object>> dmList = new ArrayList<>();
        if(null != data.getChengzhongEntityList() && !data.getChengzhongEntityList().isEmpty()) {
            //称重参数
            List<DataPidaijiChengzhong> dataPidaijiChengzhongList = data.getChengzhongEntityList();
            for(int i = 0 ; i < dataPidaijiChengzhongList.size(); i++) {
                Map<String, Object> chengzhongMap = new HashMap<>();
                chengzhongMap.put("称重序号", i + 1);
                chengzhongMap.put("输送质量", dataPidaijiChengzhongList.get(i).getZhl());
                chengzhongMap.put("称重记录时间", DateUtils.dateTime(dataPidaijiChengzhongList.get(i).getSaveTime()));
                chengzhongList.add(chengzhongMap);
            }
        }
        //速度参数
        if(null != data.getSuduEntityList() && !data.getSuduEntityList().isEmpty()) {
            DataPidaijiSudu dataPidaijiSudu = data.getSuduEntityList().get(0);
            if(null != dataPidaijiSudu) {
                params.put("最大速度", dataPidaijiSudu.getMaxSpeed());
                params.put("最大输送量", dataPidaijiSudu.getMaxShSL());
                params.put("启动时间", dataPidaijiSudu.getQdTime());
                params.put("制动时间", dataPidaijiSudu.getZhdTime());
                params.put("最大加速度", dataPidaijiSudu.getMaxAcc());
                params.put("最大减速度", dataPidaijiSudu.getMinAcc());
                params.put("速度记录时间", DateUtils.dateTime(dataPidaijiSudu.getSaveTime()));
                String suduImg = System.currentTimeMillis() + "-速度测试曲线图.png";
                if(StringUtils.isNotEmpty(dataPidaijiSudu.getSdSvg())) {
                    boolean res = ProcessPictureUtils.convertToPng(dataPidaijiSudu.getSdSvg(), rootPath + data.getDataTaskEntity().getDataTaskId() + "/" + suduImg);
                    String resString = res ? "成功" : "失败";
                    System.out.println("速度测试曲线图导入:" + resString);
                }
                params.put("速度测试曲线图", new PictureRenderData(picW, picH, rootPath + data.getDataTaskEntity().getDataTaskId() + "/" +suduImg));
            }
        }
        //径向跳动测试
        if(null != data.getJxtdEntityList() && !data.getJxtdEntityList().isEmpty()) {
            DataPidaijiJxtd dataPidaijiJxtd = data.getJxtdEntityList().get(0);
            if(null != dataPidaijiJxtd) {
                params.put("径向跳动幅度", dataPidaijiJxtd.getMaxVel());
                params.put("径向跳动记录时间", DateUtils.dateTime(dataPidaijiJxtd.getSaveTime()));
                String wyImg = System.currentTimeMillis() + "-径向跳动曲线图.png";
                if(StringUtils.isNotEmpty(dataPidaijiJxtd.getWySvg())) {
                    boolean res = ProcessPictureUtils.convertToPng(dataPidaijiJxtd.getWySvg(), rootPath + data.getDataTaskEntity().getDataTaskId() + "/" + wyImg);
                    String resString = res ? "成功" : "失败";
                    System.out.println("径向跳动曲线图导入:" + resString);
                }
                params.put("径向跳动曲线图", new PictureRenderData(picW, picH, rootPath + data.getDataTaskEntity().getDataTaskId() + "/" +wyImg));
            }
        }
        //轴向跳动测试
        if(null != data.getZxEntityList() && !data.getZxEntityList().isEmpty()) {
            DataPidaijiZx dataPidaijiZx = data.getZxEntityList().get(0);
            if(null != dataPidaijiZx) {
                params.put("轴向跳动幅度", dataPidaijiZx.getMaxVel());
                params.put("轴向跳动记录时间", DateUtils.dateTime(dataPidaijiZx.getSaveTime()));
                String wyImg = System.currentTimeMillis() + "-轴向跳动曲线图.png";
                if(StringUtils.isNotEmpty(dataPidaijiZx.getWySvg())) {
                    boolean res = ProcessPictureUtils.convertToPng(dataPidaijiZx.getWySvg(), rootPath + data.getDataTaskEntity().getDataTaskId() + "/" + wyImg);
                    String resString = res ? "成功" : "失败";
                    System.out.println("轴向跳动曲线图导入:" + resString);
                }
                params.put("轴向跳动曲线图", new PictureRenderData(picW, picH, rootPath + data.getDataTaskEntity().getDataTaskId() + "/" +wyImg));
            }
        }
        //油压测试
        if(null != data.getYyEntityList() && !data.getYyEntityList().isEmpty()) {
            DataPidaijiYy dataPidaijiYy = data.getYyEntityList().get(0);
            if(null != dataPidaijiYy) {
                params.put("最大油压", dataPidaijiYy.getMaxVel());
                params.put("油压记录时间", DateUtils.dateTime(dataPidaijiYy.getSaveTime()));
                String yyImg = System.currentTimeMillis() + "-油压曲线图.png";
                if(StringUtils.isNotEmpty(dataPidaijiYy.getYySvg())) {
                    boolean res = ProcessPictureUtils.convertToPng(dataPidaijiYy.getYySvg(), rootPath + data.getDataTaskEntity().getDataTaskId() + "/" + yyImg);
                    String resString = res ? "成功" : "失败";
                    System.out.println("油压曲线图导入:" + resString);
                }
                params.put("油压曲线图", new PictureRenderData(picW, picH, rootPath + data.getDataTaskEntity().getDataTaskId() + "/" +yyImg));
            }
        }
        //能耗测试
        if(null != data.getNhEntityList() && !data.getNhEntityList().isEmpty()) {
            DataPidaijiNh dataPidaijiNh = data.getNhEntityList().get(0);
            if(null != dataPidaijiNh) {
                params.put("电机1AB线电压", dataPidaijiNh.getDj1AbV());
                params.put("电机1BC线电压", dataPidaijiNh.getDj1BcV());
                params.put("电机1CA线电压", dataPidaijiNh.getDj1CaV());
                params.put("电机1平均电压", dataPidaijiNh.getDj1Pjdy());
                params.put("电机1电机功率", dataPidaijiNh.getDj1Djgl());
                params.put("电机1轴功率", dataPidaijiNh.getDj1Zhgl());
                params.put("电机1功率因数", dataPidaijiNh.getDj1Glysh());
                params.put("电机1负载系数", dataPidaijiNh.getDj1Fzxsh());
                params.put("电机1A相电流", dataPidaijiNh.getDj1AA());
                params.put("电机1B相电流", dataPidaijiNh.getDj1BA());
                params.put("电机1C相电流", dataPidaijiNh.getDj1CA());
                params.put("电机1平均电流", dataPidaijiNh.getDj1Pjdl());
                params.put("电机1电机效率", dataPidaijiNh.getDj1Djxl());
                params.put("电机1输出功率", dataPidaijiNh.getDj1Shchgl());
                params.put("电机1综合效率", dataPidaijiNh.getDj1Zhxl());
                params.put("电机1运行状态", dataPidaijiNh.getDj1Yxzht());
                params.put("电机1记录时间", DateUtils.dateTime(dataPidaijiNh.getSaveTime()));
                params.put("电机2AB线电压", dataPidaijiNh.getDj2AbV());
                params.put("电机2BC线电压", dataPidaijiNh.getDj2BcV());
                params.put("电机2CA线电压", dataPidaijiNh.getDj2CaV());
                params.put("电机2平均电压", dataPidaijiNh.getDj2Pjdy());
                params.put("电机2电机功率", dataPidaijiNh.getDj2Djgl());
                params.put("电机2轴功率", dataPidaijiNh.getDj2Zhgl());
                params.put("电机2功率因数", dataPidaijiNh.getDj2Glysh());
                params.put("电机2负载系数", dataPidaijiNh.getDj2Fzxsh());
                params.put("电机2A相电流", dataPidaijiNh.getDj2AA());
                params.put("电机2B相电流", dataPidaijiNh.getDj2BA());
                params.put("电机2C相电流", dataPidaijiNh.getDj2CA());
                params.put("电机2平均电流", dataPidaijiNh.getDj2Pjdl());
                params.put("电机2电机效率", dataPidaijiNh.getDj2Djxl());
                params.put("电机2输出功率", dataPidaijiNh.getDj2Shchgl());
                params.put("电机2综合效率", dataPidaijiNh.getDj2Zhxl());
                params.put("电机2运行状态", dataPidaijiNh.getDj2Yxzht());
                params.put("电机2记录时间", DateUtils.dateTime(dataPidaijiNh.getSaveTime()));
            }
        }
        //跑偏保护作用力参数
        if(null != data.getPpzylEntityList() && !data.getPpzylEntityList().isEmpty()) {
            List<DataPidaijiPpzyl> dataPidaijiPpzylList = data.getPpzylEntityList();

            for(int i = 0 ; i < dataPidaijiPpzylList.size(); i++) {
                Map<String, Object> ppMap = new HashMap<>();
                ppMap.put("跑偏序号", i + 1);
                ppMap.put("跑偏保护拉力", dataPidaijiPpzylList.get(i).getLali());
                ppMap.put("跑偏保护作用力记录时间", DateUtils.dateTime(dataPidaijiPpzylList.get(i).getSaveTime()));
                ppList.add(ppMap);
            }
        }
        //堆煤保护作用力参数
        if(null != data.getDmbhzylEntityList() && !data.getDmbhzylEntityList().isEmpty()) {
            List<DataPidaijiDmbhzyl> dataPidaijiDmbhzylList = data.getDmbhzylEntityList();

            for(int i = 0 ; i < dataPidaijiDmbhzylList.size(); i++) {
                Map<String, Object> dmMap = new HashMap<>();
                dmMap.put("堆煤序号", i + 1);
                dmMap.put("堆煤保护拉力", dataPidaijiDmbhzylList.get(i).getLali());
                dmMap.put("堆煤保护作用力记录时间", DateUtils.dateTime(dataPidaijiDmbhzylList.get(i).getSaveTime()));
                dmList.add(dmMap);
            }
        }
        params.put("堆煤保护作用力数据List", dmList);
        params.put("跑偏作用力数据List", ppList);
        params.put("称重测试数据List", chengzhongList);
        String docRootPath = RuoYiConfig.getProfile() + RuoYiConfig.getDocumentPath() + "/";
        String docFileName = System.currentTimeMillis() + "-pdj.docx";
        boolean isOk = ExportWordUtils.exportWord(RuoYiConfig.getProfile() + RuoYiConfig.getTemplatePath() + "/" + template, docRootPath, docFileName, params);
        System.out.println("isOK: 生成测试报告" + isOk + " docFileName: " + docFileName);
        return "/profile/document/" + docFileName;
    }
}
